﻿// MIT License
// 开源地址：https://gitee.com/co1024/AbcMvc
// Copyright (c) 2021-2022 1024
// Abc.Mvc=Furion+EF+SqlSugar+Pear layui admin.

using Furion.ConfigurableOptions;

using Microsoft.Extensions.Configuration;
using System.Reflection;

namespace Abc.Core;

public class AppInfoOptions : IConfigurableOptionsListener<AppInfoOptions>
{
    public string Name { get; set; }
    public string Version { get; set; }
    public string Company { get; set; }

    public void OnListener(AppInfoOptions options, IConfiguration configuration)
    {
        Type entityType = GetType();//获得该类的Type

        var dics = options.GetDictionary();
        foreach (var item in dics)
        {
            PropertyInfo propertyInfo = entityType.GetProperty(item.Key);
            propertyInfo.FieldSetValue(item.Key, item.Value as object);
        }
    }

    public void PostConfigure(AppInfoOptions options, IConfiguration configuration)
    {
    }
}